package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EmergencyRecord;
import com.ruoyi.system.service.IEmergencyRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上报记录Controller
 * 
 * @author ruoyi
 * @date 2021-06-30
 */
@RestController
@RequestMapping("/system/EmergencyRecord")
public class EmergencyRecordController extends BaseController
{
    @Autowired
    private IEmergencyRecordService emergencyRecordService;

    /**
     * 查询上报记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmergencyRecord emergencyRecord)
    {
        startPage();
        List<EmergencyRecord> list = emergencyRecordService.selectEmergencyRecordList(emergencyRecord);
        return getDataTable(list);
    }

    /**
     * 导出上报记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "上报记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EmergencyRecord emergencyRecord)
    {
        List<EmergencyRecord> list = emergencyRecordService.selectEmergencyRecordList(emergencyRecord);
        ExcelUtil<EmergencyRecord> util = new ExcelUtil<EmergencyRecord>(EmergencyRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取上报记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{erId}")
    public AjaxResult getInfo(@PathVariable("erId") Long erId)
    {
        return AjaxResult.success(emergencyRecordService.selectEmergencyRecordById(erId));
    }

    /**
     * 新增上报记录
     */
//    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "上报记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmergencyRecord emergencyRecord)
    {   emergencyRecord.setErState(0L);
        emergencyRecordService.insertEmergencyRecord(emergencyRecord);
        return AjaxResult.success(emergencyRecord);
    }
    /**
     * 修改上报记录
     */
//    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "上报记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmergencyRecord emergencyRecord)
    {
        return toAjax(emergencyRecordService.updateEmergencyRecord(emergencyRecord));
    }

    /**
     * 删除上报记录
     */
//    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "上报记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{erIds}")
    public AjaxResult remove(@PathVariable Long[] erIds)
    {
        return toAjax(emergencyRecordService.deleteEmergencyRecordByIds(erIds));
    }
}
